<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/2
 * Time: 10:15
 */

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
class DrivingTariffRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'company_id' => 'required',
            'rules' => 'required|between:0,1',
            'service_type_id' => 'required',
            'name' => 'required|max:100',
            'open_time' => 'required',
            'starting_price' => 'required',
            'mileage' => 'required',
            'waiting_timeout' => 'required',
            'other_settings' => 'required',
        ];
    }

    /**
     * 验证提示信息
     * @return array
     * @Author 姿势就是力量
     */
    public function messages()
    {
        return [
            'company_id.required' => '请选择所属公司',
            'service_type_id.required' => '请选择业务类型',
            'name.required' => '请填写资费规则',
            'name.max' => '资费规则字符过长',
            'open_time.required' => '请选择启用时间',
            'starting_price.required' => '请设起步础付费规则',
            'mileage.required' => '请设置里程付费规则',
            'waiting_timeout.required' => '请设置等待规则',
            'rules.required' => '模式必须',
            'rules.between' => '模式区间0和1之间',

        ];
    }


    protected function failedValidation(Validator $validator)
    {
        throw new HttpResponseException(response()->json([
            'code' => 0,
            'data' => [],
            'msg' => $validator->errors()->first()
        ], 400));
    }
}